#pragma once

#include "SendSignalAction.h"

#include "InputPin.h"
#include "Signal.h"

namespace uml {

SendSignalAction::SendSignalAction(const QString& umlType)
    : InvocationAction(umlType) {}

void SendSignalAction::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    InvocationAction::fromJson(json, errorList);
    signal_ = JsonSerializable::create<Signal>(json.value("signal"), errorList);

    target_ = JsonSerializable::create<InputPin>(json.value("target"), errorList);

}

void SendSignalAction::toJson(QJsonObject& json) {
    InvocationAction::toJson(json);
    if (signal_) {
        QJsonObject signal_json;
        signal_->toJson(signal_json);
        json.insert("signal", signal_json);
    }
    if (target_) {
        QJsonObject target_json;
        target_->toJson(target_json);
        json.insert("target", target_json);
    }
}

/// <summary>
/// signal getter
/// The Signal whose instance is transmitted to the target.
/// </summary>
shared_ptr<Signal> SendSignalAction::signal() const {
    return signal_;
}

/// <summary>
/// signal setter
/// The Signal whose instance is transmitted to the target.
/// </summary>
void SendSignalAction::setSignal(shared_ptr<Signal> value) {
    signal_ = value;
}

/// <summary>
/// target getter
/// The InputPin that provides the target object to which the Signal instance is
/// sent.
/// </summary>
shared_ptr<InputPin> SendSignalAction::target() const {
    return target_;
}

/// <summary>
/// target setter
/// The InputPin that provides the target object to which the Signal instance is
/// sent.
/// </summary>
void SendSignalAction::setTarget(shared_ptr<InputPin> value) {
    target_ = value;
}

} // namespace uml
